package view.panels;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import controller.TurtleController;

/**
 * This is a class which creates a pane which lists all the active turtles
 * 
 * @author Nathan Klug
 * 
 */
public class HistoryList extends AbstractListPanel<String>
{

    public HistoryList(TurtleController controller)
    {
        super(controller, ListSelectionModel.SINGLE_SELECTION);
    }

    @Override
    public void eventOccurred(ListSelectionEvent event)
    {
        if (!event.getValueIsAdjusting())
        {
            int whichItem = getIndexOfFirstSelectedItem();
            if (whichItem != -1)
            {// else, the event isn't the kind of event we're looking for
                getController().parseAndEvaluate(getListItem(whichItem));
                getController().insertText("$" + whichItem);
                clearListSelection();
            }
        }
    }
}
